-
Notifications
You must be signed in to change notification settings - Fork 113
Migrate simple JSON serialization from Newtonsoft.Json to System.Text.Json #1566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
….Json Convert `FileWritingService`, `ScanCommand`, Mariner2ArtifactFilter, and `DetectorProcessingService` to use `System.Text.Json` for serialization. `LinuxScanner` retained on Newtonsoft for now due to `SyftOutput` union types requiring custom converters.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1566 +/- ##
=======================================
- Coverage 90.1% 90.1% -0.1%
=======================================
Files 426 426
Lines 35981 35975 -6
Branches 2221 2221
=======================================
- Hits 32442 32434 -8
- Misses 3079 3080 +1
- Partials 460 461 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates JSON serialization from Newtonsoft.Json to System.Text.Json for four files: FileWritingService, ScanCommand, Mariner2ArtifactFilter, and DetectorProcessingService. The migration focuses on straightforward serialization scenarios, while complex use cases (like LinuxScanner with union types) remain on Newtonsoft.Json. The changes maintain backward compatibility by keeping model classes dual-annotated with both Newtonsoft.Json and System.Text.Json attributes during the transition.
Key Changes
- Replaced direct
JsonSerializerandJsonTextWriterusage withSystem.Text.Json.JsonSerializerstatic methods - Added
JsonSerializerOptionsconfiguration withJavaScriptEncoder.UnsafeRelaxedJsonEscapingandWriteIndentedsettings inFileWritingService - Updated imports: removed
using Newtonsoft.Json;and addedusing System.Text.Json;(andSystem.Text.Encodings.Webwhere needed)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs | Updated telemetry serialization to use System.Text.Json |
| src/Microsoft.ComponentDetection.Orchestrator/Commands/ScanCommand.cs | Migrated console output serialization to System.Text.Json with indented formatting |
| src/Microsoft.ComponentDetection.Detectors/linux/Filters/Mariner2ArtifactFilter.cs | Updated telemetry record serialization to System.Text.Json |
| src/Microsoft.ComponentDetection.Common/FileWritingService.cs | Refactored file writing methods to use System.Text.Json with custom serialization options including relaxed JSON escaping |
src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs
Show resolved
Hide resolved
58d9a84 to
9fd0bfc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.
src/Microsoft.ComponentDetection.Contracts/TypedComponent/TypedComponent.cs
Show resolved
Hide resolved
868c94e to
dc179eb
Compare
dc179eb to
788c53e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 25 out of 25 changed files in this pull request and generated no new comments.
…perties when the compile-time type is a base class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.
|
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
Convert
FileWritingService,ScanCommand,Mariner2ArtifactFilter, andDetectorProcessingServiceto useSystem.Text.Jsonfor serialization.LinuxScannerretained on Newtonsoft for now due toSyftOutputunion types requiring custom converters.